package com.sx.basic;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @author AdinZ
 * @date 2020/11/7 11:52
 */
@Data
public class ResponseEntity<T> extends BasicEntity{

    public static final int CODE_SUCCESS=200;
    public static final int CODE_ERROR=300;
    public static final int CODE_AUTHOR_FAIL=401;
    public static final int CODE_TOKEN_FAIL=403;

    @ApiModelProperty("返回状态码")
    private int code;
    @ApiModelProperty("返回消息")
    private String message;
    @ApiModelProperty("分页查询时总条数")
    private Long total;
    @ApiModelProperty("返回数据泛类")
    private T data;
    public ResponseEntity(){}
    public ResponseEntity(int code, String message) {
        this();
        this.code = code;
        this.message = message;
    }

    public ResponseEntity toError(int code,String message){
        return new ResponseEntity(code,message);
    }
    public ResponseEntity toError(String message){
        return toError(300,message);
    }
    public ResponseEntity toError(){
        return toError("参数错误");
    }
    public ResponseEntity toSuccess(String message,T data){
        ResponseEntity response=new ResponseEntity(CODE_SUCCESS,message);
        response.setData(data);
        return response;
    }
    public ResponseEntity toSuccess(T data){
        return toSuccess("",data);
    }
    public ResponseEntity toSuccess(){
        return toSuccess(null);
    }

    public ResponseEntity setTotal(long total){
        this.total=total;
        return this;
    }




}
